<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;
use app\admin\model\Slide as SlideModel;
class Slide extends Controller
{
    /**
     * 轮播图列表
     *
     * @return \think\Response
     */
    public function index()
    {
        $model=db('slide')->select();
        return view('',compact('model'));
    }


    /**
     * 轮播图添加
     */
    public function post(){

        $sid=input('param.sid');
        $model=$sid? SlideModel::find($sid) : new SlideModel();
        if (Request::instance()->isPost()){
            $post=input('post.');

            $res=$model->validate(true)->allowField(true)->save($post);
            if ($res){
                $this->success('轮播图添加成功');
            }else{
                $this->error($model->getError());
            }
        }
        if (!$sid){
            $model=[
                'slide_title'=>'','slide_url'=>'','slide_img'=>'','slide_sort'=>8
            ];
        }
        return view('',compact('model'));
    }

}
